<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            background-color: aqua;
            width: 200px;
            height: 200px;
        }
    </style>
</head>
<body>
    <script>
        window.addEventListener('load',function(){
            var div = document.querySelector('div')
            //window.resize事件 会随着当前的浏览器的窗口发生变化时自动触发
            window.addEventListener('resize',function(){
                console.log(window.innerWidth)
                //window.innerWidth 输出当前浏览器窗口的宽度
                //当浏览器的窗口宽度小于500 将div隐藏
                if(window.innerWidth<=500){
                    div.style.display = "none"
                } else{
                    div.style.display = "block"
                }
            })
        })
    </script>
    <div>

    </div>
</body>
</html>